<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <parent>
    <groupId>org.encuestame</groupId>
    <artifactId>encuestame-js</artifactId>
    <version>1.5.1-SNAPSHOT</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>
  <artifactId>resources-enme-war</artifactId>
  <packaging>war</packaging>
  <name>Encuestame Resources :: JavaScript</name>
  <profiles>
    <profile>
      <id>production</id>
      <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>wagon-maven-plugin</artifactId>
                <version>1.0-beta-1</version>
                <executions>
                    <execution>
                        <id>download-dojo</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>download-single</goal>
                        </goals>
                        <configuration>
                            <serverId>dojotoolkit</serverId>
                            <url>http://download.dojotoolkit.org/release-${dojo.version}</url>
                            <fromFile>dojo-release-${dojo.version}-src.tar.gz</fromFile>
                            <toDir>${project.build.directory}</toDir>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>${maven-antrun-plugin}</version>
            <executions>
               <execution>
                    <id>unpack</id>
                    <configuration>
                        <tasks>
                            <untar compression="gzip" src="${project.build.directory}/dojo-release-${dojo.version}-src.tar.gz" dest="${project.build.directory}/temp" />
                            <!--<untar compression="gzip"-->
                                   <!--src="/Users/jpicado/bin/dojo-release-${dojo.version}-src.tar.gz"-->
                                   <!--dest="${project.build.directory}/temp" />-->
                        </tasks>
                    </configuration>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
               </execution>
              <execution>
                <id>js</id>
                <phase>compile</phase>
                <configuration>
                    <!--<classpath>-->
                        <!--<pathelement location="${basedir}/src/main/resources/js/util/shrinksafe/js.jar" />-->
                        <!--<pathelement location="${basedir}/src/main/resources/js/util/closureCompiler/compiler.jar" />-->
                    <!--</classpath>-->
                    <target>
                        <move todir="${project.build.directory}/temp/dojo-src/js/">
                            <fileset dir="${project.build.directory}/temp/dojo-release-${dojo.version}-src" />
                        </move>
                        <echo message=" ************* COPY RESOURCES *************" />
                        <copy todir="${project.build.directory}/temp/dojo-src" verbose="false">
                            <fileset dir="${basedir}/src/main/resources/resource/">
                                <exclude name="**/js/**/dojo/**" />
                                <exclude name="**/js/**/dojox/**" />
                                <exclude name="**/js/**/dijit/**" />
                                <exclude name="**/js/**/node_modules/**" />
                                <exclude name="**/js/**/GruntFile.js" />
                                <exclude name="**/js/**/util/**" />
                            </fileset>
                        </copy>
                        <echo message="$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" />
                        <echo message="$$$$$$ ENCUESTAME DOJO COMPILE PROCESS $$$$$$$$$$$" />
                        <echo message="$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" />
                        <echo message="$$$$$$$$$$$$$ DOJO IS THE ROCK !!! $$$$$$$$$$$$$$$" />
                        <echo message="$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" />
                        <mkdir dir="${project.build.directory}/dojo-compiled" />
                        <java fork="true" failonerror="true" dir="${basedir}" classname="org.mozilla.javascript.tools.shell.Main">
                        <classpath>
                            <pathelement location="${project.build.directory}/temp/dojo-src/js/util/shrinksafe/js.jar" />
                            <pathelement location="${project.build.directory}/temp/dojo-src/js/util/closureCompiler/compiler.jar" />
                        </classpath>
                        <jvmarg value="-Xmx512M" />
                        <arg value="${project.build.directory}/temp/dojo-src/js/dojo/dojo.js" />
                        <arg value="baseUrl=${project.build.directory}/temp/dojo-src/js/dojo" />
                        <arg value="load=build" />
                        <arg value="--require" />
                        <arg value="${project.build.directory}/temp/dojo-src/js/run.js" />
                        <arg value="--profile" />
                        <arg value="${project.build.directory}/temp/dojo-src/profiles/me.profile.js" />
                        <arg value="--releaseDir" />
                        <arg value="${project.build.directory}/dojo-compiled" />
                    </java>
                    <delete includeEmptyDirs="true" verbose="false">
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dojo" includes="tests/**/" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dojo" includes="**/tests/**/" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dojo" includes="**/demos/**/" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dojo" includes="util/**" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dojo" includes="**/*.psd" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dojo" includes="**/*.fla" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dojo" includes="**/*.svg" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dojo" includes="**/*.as" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dojo" includes="**/*.swf" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release/dijit/themes/" excludes="**/claro/**/" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release" includes="**/package.json" />
                      <fileset dir="${project.build.directory}/dojo-compiled/release" includes="**/package.js" />
                    </delete>
                    <echo message="ENCUESTAME :: Dojo AMD optimized ::" />
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>

            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
              <packagingExcludes>
                WEB-INF/classes/build.sh,
                *.jar,
                resource/js/util/
              </packagingExcludes>
              <archive>
                <manifest>
                  <addClasspath>true</addClasspath>
                  <classpathPrefix>lib/</classpathPrefix>
                </manifest>
              </archive>
              <webResources>
                <resource>
                  <directory>${project.build.directory}/dojo-compiled/release</directory>
                  <targetPath>resource/js</targetPath>
                </resource>
                  <resource>
                      <directory>${basedir}/src/main/resources/resource/js/widget</directory>
                      <includes>
                          <include>build/*</include>
                          <include>dist/*</include>
                      </includes>
                      <targetPath>resource/js/widget</targetPath>
                  </resource>
              </webResources>
            </configuration>
            <version>${maven.war.plugin}</version>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  <dependencies>
    <dependency>
      <groupId>org.encuestame</groupId>
      <artifactId>encuestame-css</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.encuestame</groupId>
      <artifactId>deps</artifactId>
        <version>${project.version}</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>com.google.javascript</groupId>
      <artifactId>closure-compiler</artifactId>
      <version>v20141120</version>
    </dependency>
    <dependency>
      <groupId>rhino</groupId>
      <artifactId>js</artifactId>
      <version>1.7R2</version>
    </dependency>
  </dependencies>

</project>